package fy.EAM.dao;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.message.impl.MsgObject;
import com.soa.eis.adapter.framework.requester.IServiceRequester;
import com.soa.eis.adapter.framework.requester.impl.BaseServiceRequester;

import fy.EAM.bean.maintenancebean;
import fy.mdm.dao.MaterialRequestNoTimerTask;


public class maintenancedao {
	private static Log log = LogFactory.getLog(maintenancedao.class);
	private maintenancebean maintenancebean;
	
	public boolean getMaintenance() {
//		System.err.println("数据进入");
		try {
			for (int i = 0; i < maintenancebean.getSparePartsCode().size(); i++) {
							
			IServiceRequester Requester = BaseServiceRequester.getInstance();
			List<GroupRecord> grs1 = new ArrayList<GroupRecord>();//多层用
			// 定义请求报文对象
			IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
			String SourceSysID = "06004"; // 请求方(发布方)
			String ServiceID = "02012000000003";// 响应方(发布方)
			// 获取系统时间
			Date date = new Date();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			String format = simpleDateFormat.format(date);
			// 对请求报文对象进行设置
			reqMo.setSourceSysID(SourceSysID); // 设置报文 请求方系统号
			reqMo.setSerialNO(format.substring(0, 8) + SourceSysID
					+ String.format("%06d", ++MaterialRequestNoTimerTask.requestNo));// 设置报文流水号,第三段表示今天发送的第几的一次报文
			reqMo.setServiceID(ServiceID); // 设置报文 提供方服务号
			reqMo.setServiceDateTime(format); // 设置报文 日期时间

			reqMo.setReqValue("orderId", maintenancebean.getOrderId());
			reqMo.setReqValue("proposer", maintenancebean.getProposer());
			reqMo.setReqValue("userId", maintenancebean.getUserId());
			reqMo.setReqValue("applyDepartment", maintenancebean.getApplyDepartment());
			reqMo.setReqValue("assetName", maintenancebean.getAssetName());
			reqMo.setReqValue("AssetNumber", maintenancebean.getAssetNumber());
			reqMo.setReqValue("telphone", maintenancebean.getTelphone());
			reqMo.setReqValue("faultCause", maintenancebean.getFaultCause());
			reqMo.setReqValue("assetModel", maintenancebean.getAssetModel());
			reqMo.setReqValue("SerialNumber", maintenancebean.getSerialNumber());
			reqMo.setReqValue("status", maintenancebean.getStatus());
			reqMo.setReqValue("allocation", maintenancebean.getAllocation());
			reqMo.setReqValue("suggestion", maintenancebean.getSuggestion());			
			reqMo.setReqValue("remark", maintenancebean.getRemark());
			reqMo.setReqValue("cmpCode", maintenancebean.getCmpCode());
			GroupRecord gr1 = new GroupRecord();
			gr1.setName("WorkOrder");
			gr1.setFieldValue("sparePartsCode",maintenancebean.getSparePartsCode().get(i));
			gr1.setFieldValue("sparePartsQuantity",maintenancebean.getSparePartsQuantity().get(i));
			gr1.setFieldValue("sparePartsName",maintenancebean.getSparePartsName().get(i));
			grs1.add(gr1);
			reqMo.setReqGroupRecord(grs1);
			log.info("reqMo:"+reqMo);
//			System.err.println(reqMo);
			IMsgObject respMo = null;
			respMo = Requester.execute(reqMo);//发布报文
			
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return true;
	}

	public maintenancebean getMaintenancebean() {
		return maintenancebean;
	}

	public void setMaintenancebean(maintenancebean maintenancebean) {
		this.maintenancebean = maintenancebean;
	}
	
}
